<?php

namespace app\admin\controller\store;

use app\admin\controller\Controller;
use app\admin\model\wxapp\Wxapp as WxappModel;
use app\admin\model\store\User as StoreUser;
use Guzzle\Service\Resource\Model;
use app\factory\MqFactory;
/**
 * 板块管理
 */
class Store extends Controller{
    /**
     * 板块列表
     */
    public function index(){
        $model = new WxappModel;
        return $this->fetch('index', [
            'list' => $list = $model->getList($this->request->param()),
        ]);
    }
    /**
     * 添加板块
     */
    public function add(){
        $model = new WxappModel;
        if (!$this->request->isAjax()) {
            return $this->fetch('add');
        }
        //新增板块信息
        if ($model->add($this->postData('store'))) {
            return $this->renderSuccess('添加成功', url('store.store/index'));
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }

    /**
     * 编辑板块信息
     */
    public function edit($id){
        $model = WxappModel::detail($id);
        if (!$this->request->isAjax()) {
            return $this->fetch('edit', compact('model'));
        }
        //更新记录
        if ($model->edit($this->postData('store'))){
            return $this->renderSuccess('更新成功', url('store.store/index'));
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
    /**
     * 删除板块recover
     */
    public function delete($id){
        //板块详情
        $model=WxappModel::detail($id);
        if (!$model->setDelete()) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
    /**
     * 恢复板块
     */
    public function recover($id){
        //板块详情
        $model=WxappModel::detail($id);
        if (!$model->recover()) {
            return $this->renderError('恢复失败');
        }
        return $this->renderSuccess('恢复成功');
    }
}